Skip to content

Add Cinder quota, usage and default-class queries - #10

Merged
Mohammed Naser (mnaser) merged 1 commit into
vexxhost:mainfrom
samaritanark:contrib/cinder-quotas-2b1
Dec 4, 2026
Merged

Mohammed Naser (mnaser) merged 1 commit into
vexxhost:mainfrom
samaritanark:contrib/cinder-quotas-2b1

Conversation

@legit-ninja

@legit-ninja Jeremy Lee (legit-ninja) commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Add Cinder quota, usage and default-class queries

Summary

Add independent, read-only Cinder quota queries for retrieving active project limits, quota usage, and default-class limits without requiring callers to reconstruct these values from existing joined queries.

Motivation

The existing quota-led QuotaGetAllWithUsage join omits projects that have usage but no explicit quota override, does not expose reserved, and multiplies limit rows when several usage rows match. Reading limits, usage and class defaults separately lets callers resolve effective limits themselves: project override, then the default class, then service configuration.

Behavior

  • Rows with a NULL or empty project ID are excluded, because Cinder quota rows belong to Keystone projects.
  • Results are ordered by project, resource and row ID, so callers that collapse duplicates get a stable result.
  • Duplicate active rows, NULL limits, zero limits and -1 (unlimited) are returned as stored.
  • Usage is Cinder's cached accounting, not a live count of volumes and snapshots. reserved already counts open reservations.
  • ParseQuotaResource matches Cinder's known global resources and per-type parts (volumes, gigabytes, snapshots), so backup_gigabytes and type names that contain underscores are not misread. Keys hold the type name, not its ID, and remain after a type is deleted.

Changes

  • Add QuotaGetActiveLimits, QuotaGetActiveUsage, and QuotaGetDefaultClassLimits.
  • Add a QuotaRepository facade for quota reads and current volume-type retrieval.
  • Preserve duplicate rows, nullable values, unlimited/zero limits, and complete resource keys.
  • Extend the Cinder test schema with quota_classes.
  • Add Go unit and MariaDB integration coverage for quota behavior and existing Cinder API compatibility.
  • Add portable Python/SQLite SQL smoke tests and enable their discovery in GitHub Actions.
  • Document the new APIs and their semantics.

Compatibility

The changes are additive. Existing Cinder queries, exported signatures, volume filters, and attachment behavior are preserved.

The quota_classes addition is part of the embedded schema fixture used for tests and code generation; it is not a production database migration.

Validation

  • Reproducible generation with sqlc v1.30.0.
  • Full Go unit and race tests passed.
  • go vet and formatting checks passed.
  • Seven portable SQL tests passed, including GitHub Actions discovery.
  • Native MariaDB integration tests and existing Cinder regression tests passed locally on a Docker-enabled development machine.

The Python/SQLite tests provide fast, Docker-free checks of selected SQL semantics. They are complementary to the native MariaDB tests, not a substitute for them. Because SQLite differs from MariaDB in schema syntax and comparison behavior, the native integration suite remains the database-compatibility check.

We're open to adjustments to the testing approach or public API organization if maintainers prefer different conventions.

@mnaser Mohammed Naser (mnaser) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SQL queries (QuotaGetAllByProject, QuotaUsageGetAllByProject, QuotaClassGetDefaults), ParseQuotaResource helper, and sqlc generation all look solid—thanks for cleaning these up in the second commit to align with the rest of openstackdb.

A few items to address before we run CI and merge:

  1. Rebase onto main to resolve the merge conflict in API.md (from Designate #9).
  2. Update the PR title and description to match the final code, and squash the two commits into one clean commit (keeping DCO sign-off). Right now the title is the raw branch name (Contrib/cinder quotas 2b1) and the description still describes commit 1 (QuotaGetActiveLimits, QuotaRepository, Python/SQLite tests, and CI workflow edits).
  3. Move the detailed Cinder quota docs from README.md into API.md: README.md is meant to stay a concise overview (as in #13 and Designate #9, which only add a summary table entry to README.md and put detailed query semantics in API.md).
  4. Fixture nit: In tests/fixtures/cinder_quotas.sql, use deleted = 1 for soft-deleted rows rather than 3/4/5, since Cinder's deleted column is a boolean tinyint(1) (unlike Nova/Manila's integer row-ID soft-delete).
  5. Optional: Consider adding smoke calls for the three new queries to TestCinderQueries in tests/queries_test.go for consistency with #11 and #12. Also note that ParseQuotaResource looks clean as a library helper, though your exporter PR (#162) currently doesn't call it—worth confirming whether you plan to wire it up there.

Add three read-only Cinder quota queries, named after the Cinder DB API
functions they follow, that read every project at once and return raw
rows:

- QuotaGetAllByProject: active project limits from quotas.
- QuotaUsageGetAllByProject: cached in_use and reserved counters from
  quota_usages, including projects without limit overrides.
- QuotaClassGetDefaults: limits of the persisted default quota class.

Rows with a NULL or empty project ID are excluded, because Cinder quota
rows belong to Keystone projects. Results are ordered by project,
resource and row ID. Duplicate rows, NULL, zero and -1 limits are
returned as stored. The existing exporter quota queries are unchanged.

Add ParseQuotaResource, which splits per-volume-type keys
("<part>_<volume type name>") using Cinder's known parts and global
resource names, so backup_gigabytes and type names with underscores are
not misread.

Add quota_classes to the Cinder schema fixture, a MariaDB integration
test with a quota fixture, smoke calls in TestCinderQueries, and API.md
documentation.

Co-authored-by: David Hulick <dave.hulick@gmail.com>
Signed-off-by: David Hulick <dave.hulick@gmail.com>
Signed-off-by: Jeremy Lee <jeremy.lee1664@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@mnaser Mohammed Naser (mnaser) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates—CI is green, approving and merging.

@mnaser
Mohammed Naser (mnaser) merged commit ddb4151 into vexxhost:main Dec 4, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants